//
//  HomeViewController.swift
//  CXWeibo
//
//  Created by 陈旭 on 16/9/10.
//  Copyright © 2016年 陈旭. All rights reserved.
//

import UIKit

class HomeViewController: BaseViewController{
    // MARK:- 属性
    
    // MARK:- 懒加载属性
    private lazy var titleBtn: TitleButton = TitleButton()
    private lazy var popoverAnimator : PopoverAnimator = PopoverAnimator { (isPresented) -> () in
        self.titleBtn.selected = isPresented
    }
    
    // MARK:- 系统回调函数
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 没有登陆时设置的内容
        visitorView.addRotationAnim()
        if !isLogin{
            return
        }
        
        // 设置导航栏
        setupNavigationBar()
    }
}

// MARK:- 设置UI界面
extension HomeViewController{
    private func setupNavigationBar(){
        // 设置左右两边的item
        navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_friendattention")
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop")
        
        // 设置titleView
        titleBtn.setTitle("首页", forState: .Normal)
        navigationItem.titleView = titleBtn;
        titleBtn.addTarget(self, action: "titleBtnClick:", forControlEvents: .TouchUpInside)
    }
}

// MARK:- 事件监听
extension HomeViewController{
    @objc private func titleBtnClick(titleBtn : TitleButton){
        
        // 创建弹出的控制器
        let popoverVc = PopoverViewController()
        // 设置控制器的modal样式，一般情况下modal出新控制器后，系统会自动移除下面的旧控制器，设置为Custom后就不会移除了
        popoverVc.modalPresentationStyle = .Custom
        // 设置控制器的转场代理
        popoverVc.transitioningDelegate = popoverAnimator
        popoverAnimator.presentedFrame = CGRectMake(100, 60, 180, 250)
        
        presentViewController(popoverVc, animated: true, completion: nil)
    }
}





